package org.example.controller;

import org.example.model.common.dtos.ResponseResult;
import org.example.model.common.vos.setmeal.SearchSetmealVo;
import org.example.model.setmeal.SetmealBasic;
import org.example.service.SetmealBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 套餐管理
 */
@CrossOrigin
@RestController
@RequestMapping("/setmeal-basic")
public class SetmealBasicController {

    @Autowired
    private SetmealBasicService setmealBasicService;

    /**
     * 新增套餐
     */
    @PostMapping("/setmeal-basic")
    public ResponseResult AddSetmealBasic(@RequestBody SetmealBasic setmealBasic) {
        return ResponseResult.okResult(setmealBasicService.InsertSetmealBasic(setmealBasic));
    }

    /**
     * 根据id查询套餐详情
     */
    @GetMapping("/setmeal-basic/{id}")
    public ResponseResult GetSetmealBasicById(@PathVariable int id) {
        return ResponseResult.okResult(setmealBasicService.SelectSetmealById(id));
    }

    /**
     * 根据条件(套餐名称模糊查询，套餐状态精确查询，套餐分类精确查询)分页查询
     */
    @GetMapping("/setmeal-list/{pageIndex}/{pageSize}")
    public ResponseResult GetSetmealListByConditions(SearchSetmealVo searchSetmealVo,@PathVariable int pageIndex,@PathVariable int pageSize) {
        return ResponseResult.okResult(setmealBasicService.SelectPageByConditions(searchSetmealVo,pageIndex,pageSize));
    }

    /**
     * 根据id修改菜品
     */
    @PutMapping("/setmeal-basic")
    public ResponseResult UpdateSetmealBasicById(@RequestBody SetmealBasic setmealBasic) {
        return ResponseResult.okResult(setmealBasicService.UpdateSetmealBasicById(setmealBasic));
    }

    /**
     * 根据id删除套餐信息
     */
    @DeleteMapping("/setmeal-basic/{id}")
    public ResponseResult DeleteSetmealBasicById(@PathVariable int id) {
        return ResponseResult.okResult(setmealBasicService.DeleteSetmealBasicById(id));
    }

    /**
     * 根据id修改套餐状态
     */
    @PutMapping("/status/{id}")
    public ResponseResult UpdateSetmealStatusById(@PathVariable int id) {
        return ResponseResult.okResult(setmealBasicService.UpdateSetmealStatusById(id));
    }

    /**
     * 批量修改套餐状态
     */
    @PutMapping("/status-list/{type}")
    public ResponseResult UpdateSetmealStatusByIds(@RequestBody int[] ids,@PathVariable int type) {
        return ResponseResult.okResult(setmealBasicService.UpdateSetmealStatusByIds(ids, type));
    }

    /**
     * 批量删除套餐
     */
    @DeleteMapping("/setmeal-list")
    public ResponseResult DeleteSetmealBasicById(@RequestBody int[] ids) {
        return ResponseResult.okResult(setmealBasicService.DeleteSetmealBasicByIds(ids));
    }
}
